<template>
  <div class="Operating" id="Operating">
    <cus-Breadcrumb level1="企业管理页面" level2="企业列表  " class="mb20"></cus-Breadcrumb>
    <el-input v-model="search" placeholder="模糊搜索" ref="siteInput2" @input="loadData" class="mohu"></el-input>
    <el-input
      v-model="addNewcom"
      placeholder="新增公司"
      @keyup.enter.native="add_new_company(null, null)"
      class="add-input"
      ref="siteInput"
    ></el-input>
    <el-button @click="add_new_company(null, null)" @keyup.enter="add_new_company(null, null)">提交</el-button>
    <el-table :data="cardData" style="width: 100%" height="900">
      <el-table-column label="企业名称" width="180">
        <template slot-scope="scope">
          <div>
            <p v-if="!nameFlag">{{scope.row.departmentName}}</p>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="企业分级" width="180">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>创建时间: {{ scope.row.createTime }}</p>
            <p>修改时间: {{ scope.row.modifyTime }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">一级公司</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click.native="handleEdit(scope.$index, scope.row)" v-if="qyqyEdit">编辑</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)" v-if="qyqyDelete">删除</el-button>
          <el-button size="mini" type="primary" @click="more1(scope.$index, scope.row)" v-if="qyqySearchChild">查看子公司</el-button>
          <el-button
            size="mini"
            type="success"
            @click="searchComNumList(scope.$index, scope.row)"
            v-if="qyqySearchNumber"
          >查看企业成员</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="编辑公司" :visible.sync="nameFlag">
      <el-input v-model="edit.departmentName" placeholder="请输入公司名称" class="add-input"></el-input>
      <el-button @click="edit_company">提交</el-button>
    </el-dialog>

    <el-dialog
      :title="departmentName1 + '▶子公司'"
      :visible.sync="secondFlag"
      @opened="level=2"
      @closed="level=1"
      class="secondStyle"
      v-dialogDrag
      :close-on-click-modal="false"
      :modal="false"
    >
      <div class="tagbox">
        <el-tag type="success">添加子公司</el-tag>
        <el-tag type="success">本窗口可拖动、缩放、双击最大化</el-tag>
      </div>
      <el-input
        v-model="addNewcom2"
        ref="siteInput2"
        placeholder="请输入公司名称"
        class="add-input"
        @keyup.enter.native="add_new_company2(second.add_parentId, second.add_parentCode)"
      ></el-input>
      <el-button @click="add_new_company2(second.add_parentId, second.add_parentCode)">提交</el-button>
      <el-table :data="cardData2" style="width: 100%">
        <el-table-column label="企业名称" width="180">
          <template slot-scope="scope">
            <div>
              <p v-if="!nameFlag">{{scope.row.departmentName}}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="企业分级" width="180">
          <template slot-scope="scope">
            <el-popover trigger="hover" placement="top">
              <p>创建时间: {{ scope.row.createTime }}</p>
              <p>修改时间: {{ scope.row.modifyTime }}</p>
              <div slot="reference" class="name-wrapper">
                <el-tag size="medium">二级子公司</el-tag>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click.native="handleEdit(scope.$index, scope.row)" v-if="qyqyEdit">编辑</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)" v-if="qyqyDelete">删除</el-button>
            <el-button size="mini" type="primary" @click="more2(scope.$index, scope.row)" v-if="qyqySearchChild">查看子公司</el-button>
            <el-button
              size="mini"
              type="success"
              v-if="qyqySearchNumber"
              @click="searchComNumList(scope.$index, scope.row)"
            >查看企业成员</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog
      :title="departmentName1 + '▶' + departmentName2 + '▶子公司'"
      :visible.sync="thirdFlag"
      @opened="level=3"
      @closed="level=2"
      v-dialogDrag
      :close-on-click-modal="false"
      :modal="false"
    >
      <div class="tagbox">
        <el-tag type="success">添加子公司</el-tag>
        <el-tag type="success">本窗口可拖动、缩放、双击最大化</el-tag>
      </div>
      <el-input
        v-model="addNewcom3"
        ref="siteInput3"
        placeholder="请输入公司名称"
        class="add-input"
        @keyup.enter.native="add_new_company3(third.add_parentId, third.add_parentCode)"
      ></el-input>
      <el-button @click="add_new_company3(third.add_parentId, third.add_parentCode)">提交</el-button>
      <el-table :data="cardData3" style="width: 100%">
        <el-table-column label="企业名称" width="180">
          <template slot-scope="scope">
            <div>
              <p v-if="!nameFlag">{{scope.row.departmentName}}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="企业分级" width="180">
          <template slot-scope="scope">
            <el-popover trigger="hover" placement="top">
              <p>创建时间: {{ scope.row.createTime }}</p>
              <p>修改时间: {{ scope.row.modifyTime }}</p>
              <div slot="reference" class="name-wrapper">
                <el-tag size="medium">三级子公司</el-tag>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click.native="handleEdit(scope.$index, scope.row)" v-if="qyqyEdit">编辑</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)" v-if="qyqyDelete">删除</el-button>
            <el-button size="mini" type="primary" @click="more3 (scope.$index, scope.row)" v-if="qyqySearchChild">查看子公司</el-button>
            <el-button
              size="mini"
              type="success"
              v-if="qyqySearchNumber"
              @click="searchComNumList(scope.$index, scope.row)"
            >查看企业成员</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog
      :title="departmentName1 + '▶' +departmentName2 + '▶' +departmentName3 + '▶子公司'"
      :visible.sync="forthFlag"
      @opened="level=4"
      @closed="level=3"
      v-dialogDrag
      :close-on-click-modal="false"
      :modal="false"
    >
      <div class="tagbox">
        <el-tag type="success">添加子公司</el-tag>
        <el-tag type="success">本窗口可拖动、缩放、双击最大化</el-tag>
      </div>
      <el-input
        v-model="addNewcom4"
        ref="siteInput4"
        placeholder="请输入公司名称"
        class="add-input"
        @keyup.enter.native="add_new_company4(forth.add_parentId, forth.add_parentCode)"
      ></el-input>
      <el-button @click="add_new_company4(forth.add_parentId, forth.add_parentCode)">提交</el-button>
      <el-table :data="cardData4" style="width: 100%">
        <el-table-column label="企业名称" width="180">
          <template slot-scope="scope">
            <div>
              <p v-if="!nameFlag">{{scope.row.departmentName}}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="企业分级" width="180">
          <template slot-scope="scope">
            <el-popover trigger="hover" placement="top">
              <p>创建时间: {{ scope.row.createTime }}</p>
              <p>修改时间: {{ scope.row.modifyTime }}</p>
              <div slot="reference" class="name-wrapper">
                <el-tag size="medium">四级子公司</el-tag>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click.native="handleEdit(scope.$index, scope.row)" v-if="qyqyEdit">编辑</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)" v-if="qyqyDelete">删除</el-button>
            <el-button size="mini" type="primary" @click="more4 (scope.$index, scope.row)" v-if="qyqySearchChild">查看子公司</el-button>
            <el-button
              size="mini"
              type="success"
              v-if="qyqySearchNumber"
              @click="searchComNumList(scope.$index, scope.row)"
            >查看企业成员</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog
      :title="departmentName1 + '▶' +departmentName2 + '▶' +departmentName3 + '▶' +departmentName4 + '▶子公司'"
      :visible.sync="fivthFlag"
      @opened="level=5"
      @closed="level=4"
      v-dialogDrag
      :close-on-click-modal="false"
      :modal="false"
    >
      <div class="tagbox">
        <el-tag type="success">添加子公司</el-tag>
        <el-tag type="success">本窗口可拖动、缩放、双击最大化</el-tag>
      </div>
      <el-input
        v-model="addNewcom5"
        ref="siteInput5"
        placeholder="请输入公司名称"
        class="add-input"
        @keyup.enter.native="add_new_company5(fifth.add_parentId, fifth.add_parentCode)"
      ></el-input>
      <el-button @click="add_new_company5(fifth.add_parentId, fifth.add_parentCode)">提交</el-button>
      <el-table :data="cardData5" style="width: 100%">
        <el-table-column label="企业名称" width="180">
          <template slot-scope="scope">
            <div>
              <p v-if="!nameFlag">{{scope.row.departmentName}}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="企业分级" width="180">
          <template slot-scope="scope">
            <el-popover trigger="hover" placement="top">
              <p>创建时间: {{ scope.row.createTime }}</p>
              <p>修改时间: {{ scope.row.modifyTime }}</p>
              <div slot="reference" class="name-wrapper">
                <el-tag size="medium">五级子公司</el-tag>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click.native="handleEdit(scope.$index, scope.row)" v-if="qyqyEdit">编辑</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)" v-if="qyqyDelete">删除</el-button>
            <el-button size="mini" type="primary" @click="more5 (scope.$index, scope.row)" v-if="qyqySearchChild">查看子公司</el-button>
            <el-button
              size="mini"
              type="success"
              v-if="qyqySearchNumber"
              @click="searchComNumList(scope.$index, scope.row)"
            >查看企业成员</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog
      :title="departmentName1 + '▶' +departmentName2 + '▶' +departmentName3 + '▶' +departmentName4 + '▶' +departmentName5 + '▶子公司'"
      :visible.sync="sixthFlag"
      @opened="level=6"
      @closed="level=5"
      v-dialogDrag
      :close-on-click-modal="false"
      :modal="false"
    >
      <div class="tagbox">
        <el-tag type="success">添加子公司</el-tag>
        <el-tag type="success">本窗口可拖动、缩放、双击最大化</el-tag>
      </div>
      <el-input
        v-model="addNewcom6"
        ref="siteInput6"
        placeholder="请输入公司名称"
        class="add-input"
        @keyup.enter.native="add_new_company6(sixth.add_parentId, sixth.add_parentCode)"
      ></el-input>
      <el-button @click="add_new_company6(sixth.add_parentId, sixth.add_parentCode)">提交</el-button>
      <el-table :data="cardData6" style="width: 100%">
        <el-table-column label="企业名称" width="180">
          <template slot-scope="scope">
            <div>
              <p v-if="!nameFlag">{{scope.row.departmentName}}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="企业分级" width="180">
          <template slot-scope="scope">
            <el-popover trigger="hover" placement="top">
              <p>创建时间: {{ scope.row.createTime }}</p>
              <p>修改时间: {{ scope.row.modifyTime }}</p>
              <div slot="reference" class="name-wrapper">
                <el-tag size="medium">六级子公司</el-tag>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click.native="handleEdit(scope.$index, scope.row)" v-if="qyqyEdit">编辑</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)" v-if="qyqyDelete">删除</el-button>
            <el-button size="mini" type="primary" @click="more6 (scope.$index, scope.row)" v-if="qyqySearchChild">查看子公司</el-button>
            <el-button
              size="mini"
              type="success"
              v-if="qyqySearchNumber"
              @click="searchComNumList(scope.$index, scope.row)"
            >查看企业成员</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog
      :title="departmentName1 + '▶' +departmentName2 + '▶' +departmentName3 + '▶' +departmentName4 + '▶' +departmentName5 + '▶' +departmentName6 + '▶子公司'"
      :visible.sync="seventhFlag"
      @opened="level=7"
      @closed="level=6"
      v-dialogDrag
      :close-on-click-modal="false"
      :modal="false"
    >
      <div class="tagbox">
        <el-tag type="success">添加子公司</el-tag>
        <el-tag type="success">本窗口可拖动、缩放、双击最大化</el-tag>
      </div>
      <el-input v-model="addNewcom7" ref="siteInput7" placeholder="请输入公司名称" class="add-input"></el-input>
      <el-button @click="add_new_company7(seventh.add_parentId, seventh.add_parentCode)">提交</el-button>
      <el-table :data="cardData7" style="width: 100%">
        <el-table-column label="企业名称" width="180">
          <template slot-scope="scope">
            <div>
              <p v-if="!nameFlag">{{scope.row.departmentName}}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="企业分级" width="180">
          <template slot-scope="scope">
            <el-popover trigger="hover" placement="top">
              <p>创建时间: {{ scope.row.createTime }}</p>
              <p>修改时间: {{ scope.row.modifyTime }}</p>
              <div slot="reference" class="name-wrapper">
                <el-tag size="medium">七级子公司</el-tag>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click.native="handleEdit(scope.$index, scope.row)" v-if="qyqyEdit">编辑</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)" v-if="qyqyDelete">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog
      title="企业成员列表"
      :visible.sync="addNumber"
      v-dialogDrag
      :close-on-click-modal="false"
      :modal="false"
    >
      <div class="addFormBox">
        <el-form ref="form" :model="addForm" label-width="80px">
          <el-form-item label="姓名">
            <el-input v-model="addForm.userName"></el-input>
          </el-form-item>
          <el-form-item label="手机" label-width="80px">
            <el-input v-model="addForm.phone"></el-input>
          </el-form-item>
          <el-form-item label="工号" label-width="80px">
            <el-input v-model="addForm.staffNum"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button size="mini" type="primary" @click="handleAdd()">新增</el-button>
            <el-button size="mini" type="primary">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
    <!-- <el-pagination
      class="pagination"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="1"
      :page-sizes="[10]"
      :page-size="10"
      layout="total, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>-->
  </div>
</template>
<script>
import $$ from '@/plugins/statusCode.config'
export default {
  data () {
    return {
      qyqyEdit: false,
      qyqyDelete: false,
      qyqySearchChild: false,
      qyqySearchNumber: false,
      codeLength: sessionStorage.getItem('departmentCode').length,
      search: '',
      addForm: {
        departmentId: '',
        departmentCode: '',
        userName: '',
        phone: '',
        staffNum: ''
      },
      addNumber: false,
      total: 0,
      cardData: [],
      cardData2: [],
      cardData3: [],
      cardData4: [],
      cardData5: [],
      cardData6: [],
      cardData7: [],
      row1: {},
      row2: {},
      row3: {},
      row4: {},
      row5: {},
      row6: {},
      nameFlag: false,
      second: {
        add_parentId: '',
        add_parentCode: ''
      },
      third: {
        add_parentId: '',
        add_parentCode: ''
      },
      forth: {
        add_parentId: '',
        add_parentCode: ''
      },
      fifth: {
        add_parentId: '',
        add_parentCode: ''
      },
      sixth: {
        add_parentId: '',
        add_parentCode: ''
      },
      seventh: {
        add_parentId: '',
        add_parentCode: ''
      },
      addNewcom: '',
      addNewcom2: '',
      addNewcom3: '',
      addNewcom4: '',
      addNewcom5: '',
      addNewcom6: '',
      addNewcom7: '',
      departmentName1: '',
      departmentName2: '',
      departmentName3: '',
      departmentName4: '',
      departmentName5: '',
      departmentName6: '',
      secondFlag: false,
      thirdFlag: false,
      forthFlag: false,
      fivthFlag: false,
      sixthFlag: false,
      seventhFlag: false,
      edit: {
        departmentName: '',
        id: '',
        parentCode: ''
      },
      level: 1,
      time: 4,
      pageNo: 1
    }
  },
  mounted () {
    this.loadData()
    this.showTips()
    this.openDefault()
    this.role()
  },
  methods: {
    role () {
      let arr = JSON.parse(sessionStorage.getItem('buttonRole'))
      for (let i = 0; i < arr.length; i++) {
        if (arr[i] === 'qyqy-edit') {
          this.qyqyEdit = true
        }
        if (arr[i] === 'qyqy-delete') {
          this.qyqyDelete = true
        }
        if (arr[i] === 'qyqy-searchChild') {
          this.qyqySearchChild = true
        }
        if (arr[i] === 'qyqy-searchNumber') {
          this.qyqySearchNumber = true
        }
      }
    },
    // 页面回转开启默认的子公司菜单
    openDefault () {
      if (sessionStorage.getItem('flagArr')) {
        const flagArr = JSON.parse(sessionStorage.getItem('flagArr'))
        const rowArr = JSON.parse(sessionStorage.getItem('rowArr'))
        for (var i = 0; i < flagArr.length; i++) {
          if (flagArr[i] === 'secondFlag') {
            this.secondFlag = true
            this.more1(null, rowArr[i])
          }
          if (flagArr[i] === 'thirdFlag') {
            this.thirdFlag = true
            this.more2(null, rowArr[i])
          }
          if (flagArr[i] === 'forthFlag') {
            this.forthFlag = true
            this.more3(null, rowArr[i])
          }
          if (flagArr[i] === 'fivthFlag') {
            this.fivthFlag = true
            this.more4(null, rowArr[i])
          }
          if (flagArr[i] === 'sixthFlgag') {
            this.sixthFlgag = true
            this.more5(null, rowArr[i])
          }
          if (flagArr[i] === 'seventhFlag') {
            this.seventhFlag = true
            this.more6(null, rowArr[i])
          }
        }
        sessionStorage.removeItem('flagArr')
        sessionStorage.removeItem('rowArr')
      }
    },
    showTips () {
      const h = this.$createElement
      this.$notify({
        title: '快速录入小贴士',
        message: h(
          'i',
          { style: 'color: red' },
          '输入框用于录入企业，进入页面后输入框自动聚焦，输入公司名称后可直接敲击键盘回车Enter快速录入，页面自动重载，并再次聚焦'
        ),
        duration: 2500
      })
    },
    handleCurrentChange (val) {
      this.pageNo = val
      this.loadData()
    },
    handleSizeChange (val) {
      this.loadData(null, val)
    },
    // 查询所有一级企业 *
    async loadData () {
      this.cardData = []
      let param = new URLSearchParams()
      const that = this
      param.append(
        'code',
        sessionStorage.getItem('departmentCode') !== 'null'
          ? sessionStorage.getItem('departmentCode')
          : ''
      )
      param.append('pageNo', '')
      param.append('pageSize', 999999)
      param.append('departmentName', this.search || '')
      await this.$http8081
        .post(`/department-search/flipList`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$refs.siteInput2.focus()
            that.$message.success(res.data.statusMsg)
            const data = res.data.data.records
            that.total = res.data.data.total
            for (let i = 0; i < data.length; i++) {
              if (data[i].code.length === that.codeLength) {
                that.cardData.push(data[i])
              } else {
                that.total = that.total - 1
              }
            }
          }
        })
    },
    async more1 (index, row) {
      this.departmentName1 = row.departmentName
      this.row1 = row
      this.cardData2 = []
      this.secondFlag = true
      this.second.add_parentId = this.row1.id
      this.second.add_parentCode = this.row1.code
      let param = new URLSearchParams()
      const that = this
      param.append('code', this.row1.code)
      param.append('pageNo', '')
      param.append('pageSize', 10)
      await this.$http8081
        .post(`/department-search/flipList`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$refs.siteInput2.focus()
            that.$message.success(res.data.statusMsg)
            const data = res.data.data.records
            for (let i = 0; i < data.length; i++) {
              if (data[i].code.length === that.codeLength + 4) {
                that.cardData2.push(data[i])
                that.total = that.total++
              }
            }
          }
        })
    },
    async more2 (index, row) {
      this.departmentName2 = row.departmentName
      this.row2 = row
      this.thirdFlag = true
      this.cardData3 = []
      this.third.add_parentId = this.row2.id
      this.third.add_parentCode = this.row2.code
      let param = new URLSearchParams()
      const that = this
      param.append('code', this.row2.code)
      param.append('pageNo', '')
      param.append('pageSize', 10)
      await this.$http8081
        .post(`/department-search/flipList`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$refs.siteInput3.focus()
            that.$message.success(res.data.statusMsg)
            const data = res.data.data.records
            for (let i = 0; i < data.length; i++) {
              if (data[i].code.length === that.codeLength + 8) {
                that.cardData3.push(data[i])
              }
            }
          }
        })
    },
    async more3 (index, row) {
      this.departmentName3 = row.departmentName
      this.row3 = row
      this.forthFlag = true
      this.cardData4 = []
      this.forth.add_parentId = this.row3.id
      this.forth.add_parentCode = this.row3.code
      let param = new URLSearchParams()
      const that = this
      param.append('code', this.row3.code)
      param.append('pageNo', '')
      param.append('pageSize', 10)
      await this.$http8081
        .post(`/department-search/flipList`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$refs.siteInput4.focus()
            that.$message.success(res.data.statusMsg)
            const data = res.data.data.records
            for (let i = 0; i < data.length; i++) {
              if (data[i].code.length === that.codeLength + 12) {
                that.cardData4.push(data[i])
              }
            }
          }
        })
    },
    async more4 (index, row) {
      this.departmentName4 = row.departmentName
      this.row4 = row
      this.fivthFlag = true
      this.cardData5 = []
      this.fifth.add_parentId = this.row4.id
      this.fifth.add_parentCode = this.row4.code
      let param = new URLSearchParams()
      const that = this
      param.append('code', this.row4.code)
      param.append('pageNo', '')
      param.append('pageSize', 10)
      await this.$http8081
        .post(`/department-search/flipList`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$refs.siteInput5.focus()
            that.$message.success(res.data.statusMsg)
            const data = res.data.data.records
            for (let i = 0; i < data.length; i++) {
              if (data[i].code.length === that.codeLength + 16) {
                that.cardData5.push(data[i])
              }
            }
          }
        })
    },
    async more5 (index, row) {
      this.departmentName5 = row.departmentName
      this.row5 = row
      this.sixthFlag = true
      this.cardData6 = []
      this.sixth.add_parentId = this.row5.id
      this.sixth.add_parentCode = this.row5.code
      let param = new URLSearchParams()
      const that = this
      param.append('code', this.row5.code)
      param.append('pageNo', '')
      param.append('pageSize', 10)
      await this.$http8081
        .post(`/department-search/flipList`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$refs.siteInput6.focus()
            that.$message.success(res.data.statusMsg)
            const data = res.data.data.records
            for (let i = 0; i < data.length; i++) {
              if (data[i].code.length === that.codeLength + 20) {
                that.cardData6.push(data[i])
              }
            }
          }
        })
    },
    async more6 (index, row) {
      this.departmentName6 = row.departmentName
      this.row6 = row
      this.seventhFlag = true
      this.cardData7 = []
      this.seventh.add_parentId = this.row6.id
      this.seventh.add_parentCode = this.row6.code
      let param = new URLSearchParams()
      const that = this
      param.append('code', this.row6.code)
      param.append('pageNo', '')
      param.append('pageSize', 10)
      await this.$http8081
        .post(`/department-search/flipList`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$refs.siteInput7.focus()
            that.$message.success(res.data.statusMsg)
            const data = res.data.data.records
            for (let i = 0; i < data.length; i++) {
              if (data[i].code.length === that.codeLength + 24) {
                that.cardData7.push(data[i])
              }
            }
          }
        })
    },

    // 新增企业
    async add_new_company (parentId, parentCode) {
      const that = this
      let param = new URLSearchParams()
      param.append('departmentName', this.addNewcom)
      param.append('parentId', parentId || '')
      param.append('parentCode', parentCode || '')
      await this.$http8080
        .post(`/department-operate/save`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$message.success(res.data.statusMsg)
            that.addNewcom = ''
            that.loadData()
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    async add_new_company2 (parentId, parentCode) {
      const that = this
      let param = new URLSearchParams()
      param.append('departmentName', this.addNewcom2)
      param.append('parentId', parentId)
      param.append('parentCode', parentCode)
      await this.$http8080
        .post(`/department-operate/save`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$message.success(res.data.statusMsg)
            that.addNewcom2 = ''
            that.more1(null, that.row1)
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    async add_new_company3 (parentId, parentCode) {
      const that = this
      let param = new URLSearchParams()
      param.append('departmentName', this.addNewcom3)
      param.append('parentId', parentId)
      param.append('parentCode', parentCode)
      await this.$http8080
        .post(`/department-operate/save`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$message.success(res.data.statusMsg)
            that.addNewcom3 = ''
            that.more2(null, that.row2)
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    async add_new_company4 (parentId, parentCode) {
      const that = this
      let param = new URLSearchParams()
      param.append('departmentName', this.addNewcom4)
      param.append('parentId', parentId)
      param.append('parentCode', parentCode)
      await this.$http8080
        .post(`/department-operate/save`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$message.success(res.data.statusMsg)
            that.addNewcom4 = ''
            that.more3(null, that.row3)
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    async add_new_company5 (parentId, parentCode) {
      const that = this
      let param = new URLSearchParams()
      param.append('departmentName', this.addNewcom5)
      param.append('parentId', parentId)
      param.append('parentCode', parentCode)
      await this.$http8080
        .post(`/department-operate/save`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$message.success(res.data.statusMsg)
            that.addNewcom5 = ''
            that.more4(null, that.row4)
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    async add_new_company6 (parentId, parentCode) {
      const that = this
      let param = new URLSearchParams()
      param.append('departmentName', this.addNewcom6)
      param.append('parentId', parentId)
      param.append('parentCode', parentCode)
      await this.$http8080
        .post(`/department-operate/save`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$message.success(res.data.statusMsg)
            that.addNewcom6 = ''
            that.more5(null, that.row5)
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    async add_new_company7 (parentId, parentCode) {
      const that = this
      let param = new URLSearchParams()
      param.append('departmentName', this.addNewcom7)
      param.append('parentId', parentId)
      param.append('parentCode', parentCode)
      await this.$http8080
        .post(`/department-operate/save`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$message.success(res.data.statusMsg)
            that.addNewcom7 = ''
            that.more6(null, that.row6)
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    handleEdit (index, row) {
      this.nameFlag = true
      this.edit.departmentName = row.departmentName
      this.edit.id = row.id
      this.parentCode = row.parentCode || ''
    },
    async edit_company () {
      const that = this
      let param = new URLSearchParams()
      param.append('departmentName', this.edit.departmentName)
      param.append('parentCode', this.edit.parentCode)
      param.append('id', this.edit.id)
      await this.$http8080
        .post(`/department-operate/modify`, param)
        .then(function (res) {
          if (res.data.statusCode === $$.s20002) {
            that.$message.success(res.data.statusMsg)
            that.nameFlag = false
            if (that.level === 1) {
              that.loadData()
            }
            if (that.level === 2) {
              that.more1(null, that.row1)
            }
            if (that.level === 3) {
              that.more2(null, that.row2)
            }
            if (that.level === 4) {
              that.more3(null, that.row3)
            }
            if (that.level === 5) {
              that.more4(null, that.row4)
            }
            if (that.level === 6) {
              that.more5(null, that.row5)
            }
            if (that.level === 7) {
              that.more6(null, that.row6)
            }
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    // 删除
    async handleDelete (index, row) {
      const ids = row.id
      const that = this
      let param = new URLSearchParams()
      param.append('id', ids)
      await this.$http8080
        .post(`/department-operate/remove`, param)
        .then(async function (res) {
          if (res.data.statusCode === $$.s20004) {
            that.$message.success(res.data.statusMsg)
            if (that.level === 1) {
              that.loadData()
            }
            if (that.level === 2) {
              that.more1(null, that.row1)
            }
            if (that.level === 3) {
              that.more2(null, that.row2)
            }
            if (that.level === 4) {
              that.more3(null, that.row3)
            }
            if (that.level === 5) {
              that.more4(null, that.row4)
            }
            if (that.level === 6) {
              that.more5(null, that.row5)
            }
            if (that.level === 7) {
              that.more6(null, that.row6)
            }
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    },
    searchComNumList (index, row) {
      sessionStorage.setItem('AddDepartmentName', row.departmentName)
      this.addForm.departmentId = row.id
      this.addForm.departmentCode = row.code
      sessionStorage.setItem('addForm', JSON.stringify(this.addForm))
      const flagArr = []
      if (this.secondFlag === true) {
        flagArr.push('secondFlag')
      }
      if (this.thirdFlag === true) {
        flagArr.push('thirdFlag')
      }
      if (this.forthFlag === true) {
        flagArr.push('forthFlag')
      }
      if (this.fivthFlag === true) {
        flagArr.push('fivthFlag')
      }
      if (this.sixthFlag === true) {
        flagArr.push('sixthFlag')
      }
      if (this.seventhFlag === true) {
        flagArr.push('seventhFlag')
      }
      const rowArr = []
      if (this.row1) {
        rowArr.push(this.row1)
      }
      if (this.row2) {
        rowArr.push(this.row2)
      }
      if (this.row3) {
        rowArr.push(this.row3)
      }
      if (this.row4) {
        rowArr.push(this.row4)
      }
      if (this.row5) {
        rowArr.push(this.row5)
      }
      if (this.row6) {
        rowArr.push(this.row6)
      }
      sessionStorage.setItem('flagArr', JSON.stringify(flagArr))
      sessionStorage.setItem('rowArr', JSON.stringify(rowArr))
      const dipartmentName = {
        departmentName1: this.departmentName1,
        departmentName2: this.departmentName2,
        departmentName3: this.departmentName3,
        departmentName4: this.departmentName4,
        departmentName5: this.departmentName5,
        departmentName6: this.departmentName6
      }
      sessionStorage.setItem('dipartmentName', JSON.stringify(dipartmentName))
      this.$router.push({ name: 'AdministratorCompanyList' })
    },
    async handleAdd () {
      const that = this
      await this.$http8080
        .post(`/department-staff-operate/saveDepartmentStaff`, that.addForm)
        .then(function (res) {
          if (res.data.statusCode === $$.s20000) {
            that.$message.success('添加企业成员成功')
          } else {
            that.$message.error(res.data.statusMsg)
          }
        })
    }
  }
}
</script>
<style scope="scoped">
#Operating .addFormBox {
  width: 300px;
}
#Operating .add-input {
  width: 300px;
}
#Operating .el-dialog {
  margin-top: 15vh;
  overflow: auto;
  cursor: default;
  user-select: none;
  left: -179px;
  top: 73px;
  border: 1px solid rgb(168, 197, 242);
  box-shadow: rgb(204, 204, 204) 10px 10px 39px;
}
#Operating .tagbox {
  margin-bottom: 10px;
}
#Operating .el-dialog__title {
  font-weight: 700;
  line-height: 24px;
  font-size: 18px;
  color: crimson;
}
#Operating .pagination {
  position: absolute;
  right: 120px;
  top: 120px;
}
#Operating .mohu {
  margin-right: 100px;
  width: 300px;
}
</style>
